﻿using CrankShaftAnalysisSystem.Devices;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CrankShaftAnalysisSystem.SubForm
{
    public partial class FormFastenPart : Form
    {
        public event Action OnStepConfirmed;
        public FormFastenPart()
        {
            InitializeComponent();
        }

        private void FormFastenPart_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = true;
        }

        private void FormFastenPart_Load(object sender, EventArgs e)
        {
            tmLoop.Start();
            UIHelper.SetPanelToCenter(ref panelMain);
        }

        private void tmLoop_Tick(object sender, EventArgs e)
        {
            ledAutoOn.On = Tools.GetBitState(PLCMaster.Instance.Device.Info.ButtonInfo, VirtualDevice.Mask.AUTOON);
            ledPartFasten.On = PLCMaster.Instance.PartFastened;
        }

        private void btnConfirmed_Click(object sender, EventArgs e)
        {
            if (ledAutoOn.On && ledPartFasten.On)
            {
                if (OnStepConfirmed != null)
                {
                    OnStepConfirmed();
                }
            }
        }
    }
}
